package com.foreveross.taskservice.application.task.statsdetail.vo;

import java.math.BigDecimal;
import java.util.Date;

import org.apache.commons.lang3.time.DateFormatUtils;


public class CrawlStatsVO extends BaseVO {
	/**
	 * 
	 */
	private static final long serialVersionUID = 3842745390021161088L;
	private long channelId;
	private String channelName;
	private String channelCode;
	private String id;
	private long sum;

	private long pauseStatusCount;
	private long businessFailStatusCount;
	private long businessSuccessStatusCount;
	
	private long otherFailStatusCount;
	private long paraseFailStatusCount;
	private long fetchFailStatusCount;//抓取失败
	private long waitStatusCount;
	private long doingStatusCount;
	private long successStatusCount;
	private long bothByteLength;//抓取流量byte
	private double bothMLength;//抓取流量M
	private long crawlCount;
	
	private Date crawlDate;//抓取日期
	private String crawlDateStr;
	
	private double successRate;
	/**
	 * @param crawlDate　抓取日期
	 * @param channelId 渠道ID
	 * @param channelName 渠道名称
	 * @param channelCode　渠道编码
	 * @param pauseStatusCount　暂停数
	 * @param otherFailStatusCount　其它失败数
	 * @param paraseFailStatusCount　解析失败数
	 * @param fetchFailStatusCount　抓取失败数
	 * @param waitStatusCount　等待数
	 * @param doingStatusCount　执行中数
	 * @param businessFailStatusCount　业务失败数
	 * @param businessSuccessStatusCount　业务成功数
	 * @param successStatusCount　成功数
	 * @param bothByteLength　流量字节
	 * @param crawlCount　实际抓取对象数量

	 */
	public CrawlStatsVO(Date crawlDate, long channelId, String channelName,String channelCode, long pauseStatusCount,
			long otherFailStatusCount,  long paraseFailStatusCount,
			long fetchFailStatusCount, long waitStatusCount,
			long doingStatusCount, long businessFailStatusCount,long businessSuccessStatusCount, long successStatusCount,
			long bothByteLength, long crawlCount) {
		super();
		this.channelId = channelId;
		this.channelName = channelName;
		this.channelCode=channelCode;
		this.pauseStatusCount = pauseStatusCount;
		
		this.businessFailStatusCount = businessFailStatusCount;
		this.businessSuccessStatusCount = businessSuccessStatusCount;
		
		this.otherFailStatusCount = otherFailStatusCount;
		this.paraseFailStatusCount = paraseFailStatusCount;
		this.fetchFailStatusCount = fetchFailStatusCount;
		this.waitStatusCount = waitStatusCount;
		this.doingStatusCount = doingStatusCount;
		this.successStatusCount = successStatusCount;
		this.bothByteLength = bothByteLength;
		if(this.bothByteLength>0){
			bothMLength=bothByteLength/(1024*1024);
		}
		this.crawlCount = crawlCount;
		this.crawlDate = crawlDate;
		if(this.crawlDate!=null){
			this.crawlDateStr=DateFormatUtils.format(this.crawlDate, "yyyy-MM-dd");
		}
		this.sum=add(this.businessFailStatusCount, this.businessSuccessStatusCount, this.pauseStatusCount,
				this.otherFailStatusCount,this.paraseFailStatusCount,this.fetchFailStatusCount,
				this.waitStatusCount,this.doingStatusCount,this.successStatusCount);
		this.successRate=this.successStatusCount==0?0:
			twoDecimalPslaces(((double)(this.successStatusCount+this.businessSuccessStatusCount)/(double)(this.sum-this.waitStatusCount-this.doingStatusCount))*100);
	}
	public long getChannelId() {
		return channelId;
	}
	public String getChannelName() {
		return channelName;
	}

	public String getChannelCode() {
		return channelCode;
	}
	public void setChannelCode(String channelCode) {
		this.channelCode = channelCode;
	}
	public long getBusinessFailStatusCount() {
		return businessFailStatusCount;
	}
	public void setBusinessFailStatusCount(long businessFailStatusCount) {
		this.businessFailStatusCount = businessFailStatusCount;
	}
	public long getBusinessSuccessStatusCount() {
		return businessSuccessStatusCount;
	}
	public void setBusinessSuccessStatusCount(long businessSuccessStatusCount) {
		this.businessSuccessStatusCount = businessSuccessStatusCount;
	}
	public void setChannelId(long channelId) {
		this.channelId = channelId;
	}
	public void setChannelName(String channelName) {
		this.channelName = channelName;
	}
	public void setSum(long sum) {
		this.sum = sum;
	}
	public void setPauseStatusCount(long pauseStatusCount) {
		this.pauseStatusCount = pauseStatusCount;
	}
	public void setOtherFailStatusCount(long otherFailStatusCount) {
		this.otherFailStatusCount = otherFailStatusCount;
	}
	public void setParaseFailStatusCount(long paraseFailStatusCount) {
		this.paraseFailStatusCount = paraseFailStatusCount;
	}
	public void setFetchFailStatusCount(long fetchFailStatusCount) {
		this.fetchFailStatusCount = fetchFailStatusCount;
	}
	public void setWaitStatusCount(long waitStatusCount) {
		this.waitStatusCount = waitStatusCount;
	}
	public void setDoingStatusCount(long doingStatusCount) {
		this.doingStatusCount = doingStatusCount;
	}
	public void setSuccessStatusCount(long successStatusCount) {
		this.successStatusCount = successStatusCount;
	}
	public void setBothByteLength(long bothByteLength) {
		this.bothByteLength = bothByteLength;
	}
	public void setBothMLength(double bothMLength) {
		this.bothMLength = bothMLength;
	}
	public void setCrawlCount(long crawlCount) {
		this.crawlCount = crawlCount;
	}
	public void setCrawlDate(Date crawlDate) {
		this.crawlDate = crawlDate;
	}
	public void setCrawlDateStr(String crawlDateStr) {
		this.crawlDateStr = crawlDateStr;
	}
	public void setSuccessRate(double successRate) {
		this.successRate = successRate;
	}
	public long getPauseStatusCount() {
		return pauseStatusCount;
	}
	public long getOtherFailStatusCount() {
		return otherFailStatusCount;
	}
	public long getParaseFailStatusCount() {
		return paraseFailStatusCount;
	}
	public long getFetchFailStatusCount() {
		return fetchFailStatusCount;
	}
	public long getWaitStatusCount() {
		return waitStatusCount;
	}
	public long getDoingStatusCount() {
		return doingStatusCount;
	}
	public long getSuccessStatusCount() {
		return successStatusCount;
	}
	public long getBothByteLength() {
		return bothByteLength;
	}
	public double getBothMLength() {
		return bothMLength;
	}
	public long getCrawlCount() {
		return crawlCount;
	}
	public Date getCrawlDate() {
		return crawlDate;
	}
	public String getCrawlDateStr() {
		return crawlDateStr;
	}
	
	
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public double getSuccessRate() {
		return successRate;
	}
	public long getSum() {
		return sum;
	}
	private long add(long ...ls ){
		long sum=0;
		for(long l:ls){
			sum+=l;
		}
		return sum;
	}
	/**
	 * 保留后4位小数
	 * @param d
	 * @return
	 */
	private double twoDecimalPslaces(double d){
		BigDecimal b = new BigDecimal(d);
		return b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
	}
}
